package com.tang.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * Druid的DataResource配置类
 * @author Raye
 * @since 2018年10月7日14:14:18
 */
@Configuration
@RefreshScope
public class DataBaseConfig {

	@Value("${spring.datasource.type}")
	private Class<? extends DataSource> type;

	@Bean
	@ConfigurationProperties(prefix = "spring.datasource")
	public DataSource dataSource() throws Exception{
		return DataSourceBuilder.create().type(type).build();
	}

}
